﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EachRecord.Common.Attributes
{
    [ AttributeUsage(AttributeTargets.Property,AllowMultiple =true,Inherited =true)]
    public class ModelPropertyAttribute : MasterAttribute
    { 
        private readonly int min_length = 2;
        private readonly int max_length = 4;
        private readonly int sex_length=1;
        private readonly int password_min_length = 6;
        private readonly int password_max_length = 12;
        private readonly Boolean ISNULL = false;
        private readonly int age_min_value = 18;
        public ModelPropertyAttribute() { }

        /// <summary>
        /// 验证name合法性
        /// </summary>
        /// <param name="min_length"></param>
        /// <param name="max_length"></param>
        public ModelPropertyAttribute(int min_length, int max_length, bool iSNULL)
        {
            this.min_length = min_length;
            this.max_length = max_length;
            this.ISNULL = iSNULL;
        }

        /// <summary>
        /// 验证性别合法性
        /// </summary>
        /// <param name="gender"></param>
        public ModelPropertyAttribute(int sex_length) { 
                this.sex_length = sex_length;
        }

        /// <summary>
        /// 验证密码合法性
        /// </summary>
        /// <param name="password_min_length"></param>
        /// <param name="password_max_length"></param>
        public ModelPropertyAttribute(int password_min_length, int password_max_length) { 
          this.password_min_length=password_min_length;
            this.password_max_length=password_max_length;
        }

        /// <summary>
        /// 验证用户名
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public string ValidataUserName(string username) {
            string res = "合法";
            if (username.Length < this.min_length || username.Length > max_length)
                res = $"username长度不合法";
            return res;
        }

            
    }
}
